<template>
  <div>
    <!-- 面包屑导航区域 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>设备研制方案</el-breadcrumb-item>
      <el-breadcrumb-item>研制方案审批</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片视图区域 -->
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>单据列表</span>
      </div>

      <div>
        <el-radio-group v-model="selectStatus">
          <el-radio-button label="待审批列表" @click="toWait"></el-radio-button>
          <el-radio-button label="已通过列表" @click="toPass"></el-radio-button>
          <el-radio-button label="已驳回列表" @click="toReject"></el-radio-button>
        </el-radio-group>
      </div>
      <!-- 用户列表区域-->
      <el-table
        :data="CheckEquipmentlist"
        border
        style="width: 95%">
        <el-table-column prop="state" label="单据状态"></el-table-column>
        <el-table-column prop="ticketId" label="单据编号" ></el-table-column>
        <el-table-column prop="planId" label="方案编码"></el-table-column>
        <el-table-column prop="equipmentName" label="设备名称"></el-table-column>
        <el-table-column prop="tbName" label="填报人"></el-table-column>
        <el-table-column prop="tbDepartment" label="填报部门"></el-table-column>
        <el-table-column prop="fzName" label="负责人"></el-table-column>
        <el-table-column prop="fzDepartment" label="负责部门"></el-table-column>
        <el-table-column prop="date" label="填报日期"></el-table-column>
        <el-table-column label="操作" width="150px">
          <template slot-scope="scope">
              <el-button type="danger" size="mini" @click="reject(scope.row.ticketId)">驳回审核</el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页区域 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :total="total"
        :current-page="queryInfo.nowpage"
        :page-sizes="[1, 2, 5, 10]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
      >
      </el-pagination>
    </el-card>


  </div>
</template>

<script>
  export default {
    data () {
      return {
        selectStatus: '已通过列表',
        CheckEquipmentlist: [],
        // 控制删除票据对话框的显示与隐藏
        deleteDialogVisible: false,
        //查询到的用户对象
        editForm:{
          ticketId: 1,
          planId: '',
          budgetItem: '',
          budgetNum: '',
          remark: ''
        },
        total: 0,
        queryInfo: {
          // 当前页数
          nowpage: 1,
          // 当前每页显示多少条数据
          pagesize: 10,
          // 选择种类
          select: '',
          // 搜索内容
          searchContent: ''
        }
      }
    },

    created () {
      this.getPassEquipmentList()
    },
    methods: {
      toAddPlan () {
        this.$router.push({ path: '/addPlan' })
      },

      // 监听分页尺寸改变的事件
      handleSizeChange (newSize) {
        this.queryInfo.pagesize = newSize
        this.getEquipmentList()
      },
      // 监听当前页码值改变的事件
      handleCurrentChange (nowPage) {
        this.queryInfo.nowpage = nowPage
        this.getEquipmentList()
      },

      // 获取已通过列表
      getPassEquipmentList () {
        this.$http.get('pass-equipment-list', { params: this.queryInfo }).then(res=> {
          this.CheckEquipmentlist=[]
          for (var i = 1; i < res.data.length; i++) {
            this.CheckEquipmentlist.push(res.data[i])
          }
          this.total = res.data[0].number
        })
      },

      toWait(){
        this.$router.push({ path: '/waitEquipment' }).catch(err => {
          //console.log('输出报错',err)
        })
      },

      toPass(){
        this.$router.push({ path: '/passEquipment' }).catch(err => {
          //console.log('输出报错',err)
        })
      },

      toReject(){
        this.$router.push({ path: '/rejectEquipment' }).catch(err => {
          //console.log('输出报错',err)
        })
      },

      //根据ticketId删除对应信息
      async reject(ticketId){
        this.editForm.ticketId = ticketId;
        //弹框询问是否删除
        const confirmResult = await this.$confirm('是否确认更改单据状态为已驳回?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).catch(err => err)
        //若确认删除则返回字符串confirm,取消则为cancel
        //console.log(confirmResult)
        if(confirmResult !== 'confirm'){
          return this.$message.info('已经取消审核')
        }
        //console.log('确认了删除')
        await this.$http.put('reject-equipment', this.editForm);
        this.$message.success('驳回审核审核成功')
        this.getPassEquipmentList()
      }
    },
  }
</script>

<style lang="less" scoped>
  .el-input {
    width: 500px;
  }
  .el-select {
    width: 110px;
  }
  .input-with-select .el-input-group__prepend {
    background-color: #fff;
  }
  .el-table {
    margin-top: 15px;
    font-size: 12px;
  }
  .el-pagination {
    margin-top: 15px;
  }
</style>
